//% color="#3676b8" iconWidth=50 iconHeight=40
namespace yunque{

    //% block="yunque module initialization until successful I2C mode address 0x42" blockType="command" 
    export function init(parameter: any, block: any) {

        Generator.addInclude("DFRobot_Atmospherlum", `#include "DFRobot_Atmospherlum.h"`);
        Generator.addObject(`object`, `DFRobot_Atmospherlum_I2C `, `atm(0x42,&Wire);`);
        Generator.addCode(`while(atm.begin()!=0){delay(1000);}`);
   
    }

    //% block="yunque set time [YEAR]/[MON]/[DAY] [HOUR]:[MIN]:[SEC]" blockType="command"
    //% YEAR.shadow="number"   YEAR.defl="2022"
    //% MON.shadow="number"   MON.defl="12"
    //% DAY.shadow="number"   DAY.defl="8"
    //% HOUR.shadow="number"   HOUR.defl="11"
    //% MIN.shadow="number"   MIN.defl="0"
    //% SEC.shadow="number"   SEC.defl="0"
    export function setTime(parameter: any, block: any) { 
        let year = parameter.YEAR.code;
        let month = parameter.MON.code;
        let day = parameter.DAY.code;
        let hour = parameter.HOUR.code;
        let minute = parameter.MIN.code;
        let second = parameter.SEC.code;
        Generator.addCode(`atm.setTime(${year},${month},${day},${hour},${minute},${second});`)
   
   } 

       //% block="yunque get time stamp" blockType="reporter"
    export function getTime(parameter: any, block: any) { 
        Generator.addCode( [`atm.getTimeStamp()`,Generator.ORDER_UNARY_POSTFIX]);
   
   } 

    //% block="yunque get [VDAT] value" blockType="reporter"
    //% VDAT.shadow="dropdown"   VDAT.options="VDAT"
    export function getValueDate(parameter: any, block: any) { 
        let dat = parameter.VDAT.code;
        Generator.addCode( [`atm.getValue("${dat}")`,Generator.ORDER_UNARY_POSTFIX]);
   
   } 


    //% block="yunque get [UDAT] unit" blockType="reporter"
    //% UDAT.shadow="dropdown"   UDAT.options="UDAT"
    export function getUnitDate(parameter: any, block: any) { 
        let dat = parameter.UDAT.code;
        Generator.addCode( [`atm.getUnit("${dat}")`,Generator.ORDER_UNARY_POSTFIX]);
   
   } 
    //% block="yunque get [STR] [VOU]" blockType="reporter"
    //% STR.shadow="string"   STR.defl=" "
    //% VOU.shadow="dropdown"   VOU.options="VOU"
    export function getSingleDate(parameter: any, block: any) { 
        let st = parameter.STR.code;
        let vou = parameter.VOU.code;
        Generator.addCode( [`atm.get${vou}(${st})`,Generator.ORDER_UNARY_POSTFIX]);
   
   } 

    //% block="yunque get all data unit[TOF]" blockType="reporter"
    //% TOF.shadow="dropdown"   TOF.options="TOF"
    export function getAllDate(parameter: any, block: any) { 
        let tof = parameter.TOF.code;
        //tof=tof.replace(/"/g, "")
        Generator.addCode( [`atm.getInformation(${tof})`,Generator.ORDER_UNARY_POSTFIX]);
   
   } 


}